package greedy;

/**
 * @Author: 海琳琦
 * @Date: 2022/2/26 22:27
 * https://leetcode-cn.com/problems/wiggle-subsequence/
 */
public class WiggleMaxLength {

    /**
     * 贪婪：让峰值尽可能的保持峰值，然后删除单一坡度上的节点。
     * @param nums
     * @return
     */
    public int wiggleMaxLength(int[] nums) {
        //结点左边坡度
        int leftGap = 0;
        //结点右边的坡度
        int rightGap = 0;
        int count = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            rightGap = nums[i + 1] - nums[i];
            //出现峰值
            if ((rightGap > 0 && leftGap <= 0) || (rightGap < 0 && leftGap >= 0)) {
                count++;
                leftGap = rightGap;
            }
        }
        //最后一个结点默认峰值
        return count + 1;
    }

    public static void main(String[] args) {

    }
}
